
if( NOT EXECUTABLE_OUTPUT_PATH) 
  message(FATAL_ERROR "Key EXECUTABLE_OUTPUT_PATH must have been set before running ConfigureOgre.cmake")
endif()


SET( RUNTIME_SEARCH_DIRS ${CMAKE_SOURCE_DIR}/../runtime )

#
# Generate plugins.cfg and copy OgreMain.dll
#

# Find plugin dir
find_path( OGRE_PLUGIN_DIRECTORY NAMES OgreMain.dll release/OgreMain.dll
 PATHS ${RUNTIME_SEARCH_DIRS})
if( NOT OGRE_PLUGIN_DIRECTORY )
  message( STATUS "Unable to find runtime dir" )
else()
  message( STATUS "Found plugin directory: ${OGRE_PLUGIN_DIRECTORY}" )
endif()

SET( PLUGIN_LIST 
  "RenderSystem_Direct3D9"
  "RenderSystem_GL"
  "Plugin_BSPSceneManager"
  "Plugin_OctreeSceneManager"
  "Plugin_ParticleFX"
)

MACRO( SET_PLUGINS _postfix )
  FOREACH( PLUGIN ${PLUGIN_LIST})
    SET( PLUGIN_FILE "${OGRE_PLUGIN_DIRECTORY}/${PLUGIN}${_postfix}.dll" )
    IF(EXISTS  ${PLUGIN_FILE})   
      SET( Ogre_${PLUGIN}_LINE "Plugin=${PLUGIN}${_postfix}" )
    ELSE()
      SET( Ogre_${PLUGIN}_LINE "#Plugin=${PLUGIN}${_postfix}" )
    ENDIF()
  ENDFOREACH()
ENDMACRO()



# generate / copy the actual files (but only if something was found)
SET_PLUGINS( "" )
CONFIGURE_FILE( plugins.cfg.in ${EXECUTABLE_OUTPUT_PATH}/Release/plugins.cfg )

SET_PLUGINS( "_d" )
CONFIGURE_FILE( plugins.cfg.in ${EXECUTABLE_OUTPUT_PATH}/Debug/plugins.cfg )
    
CONFIGURE_FILE( ${OGRE_PLUGIN_DIRECTORY}/OgreMain.dll ${EXECUTABLE_OUTPUT_PATH}/Release/OgreMain.dll COPYONLY )
CONFIGURE_FILE( ${OGRE_PLUGIN_DIRECTORY}/OgreMain_d.dll ${EXECUTABLE_OUTPUT_PATH}/Debug/OgreMain_d.dll COPYONLY )


CONFIGURE_FILE( resources.cfg.in ${EXECUTABLE_OUTPUT_PATH}/Release/resources.cfg)
CONFIGURE_FILE( resources.cfg.in ${EXECUTABLE_OUTPUT_PATH}/Debug/resources.cfg)
